package Lee_code;

import java.util.HashMap;

/**
 * @author blh
 * @date 2024年10月24日 10:48
 */
public class Lee_290_1024 {
    public boolean wordPattern(String pattern, String s) {
        String[] strs = s.split(" ");
        HashMap<Character, String> hashMap = new HashMap<>();
        if (pattern.length() != strs.length) {
            return false;
        }
        for (int i = 0; i < strs.length; i++) {
            char tempKey = pattern.charAt(i);
            String tempValue = strs[i];
            if (hashMap.containsKey(tempKey)) {
                if (!hashMap.get(tempKey).equals(tempValue)) {
                    return false;
                }
            } else {
                if (hashMap.containsValue(tempValue)) {
                    return false;
                }
                hashMap.put(tempKey, tempValue);
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Lee_290_1024 method = new Lee_290_1024();
        method.wordPattern("abba", "dog cat cat fish");
    }
}
